﻿#region
/* ===============================================
 * 作者：guopeng           时间：2012/2/4 10:21:12
 * 
 * 
 * 类描述：商家实体
 * 考虑代理情况，可能一个用户代理着N个商家的扩展
 * 
 * =============================================== */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using ueEngine.Biz.Inf.Entities.DBSupport;
using ueEngine.Framework.Exception;
using ueEngine.Framework.Caching;

namespace ueEngine.Biz.Inf.Entities
{
    /// <summary>
    /// 商家公司信息。
    /// 一个企业代理只能维护一个公司信息。
    /// 但可以维护N个代理企业信息 （代理企业信息是该代理人代表其进行招募的信息集合）
    /// </summary>
    [Table("Corporation")]
    public class Corporation : BaseEntity<Corporation>
    {
        public Corporation() { }
        public override Corporation Get(System.Linq.Expressions.Expression<Func<Corporation, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Corporation.FirstOrDefault(where);
                if (item != null)
                {
                    this.About = item.About;
                    this.Agent = item.Agent;
                    this.CompanyName = item.CompanyName;
                    this.EMail = item.EMail;
                    this.Id = item.Id;
                    //this.Identification = item.Identification;
                    this.Location = item.Location;
                    this.Phone = item.Phone;
                    //this.CertificationId = item.CertificationId;
                    this.CertificationLevel = item.CertificationLevel;
                    return this;
                }
                return null;
            }
        }
        #region Fileds
        /// <summary>
        /// 商家Id
        /// </summary>
        [Column("Id",TypeName="int")]
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        /// <summary>
        /// 代理人。对应Member中用户名
        /// </summary>
        [Column("Agent",TypeName="varchar")]
        [StringLength(200)]
        [Required]
        public string Agent { get; set; }

        /// <summary>
        /// 商家名
        /// </summary>
        [Column("CompanyName",TypeName="nvarchar")]
        [StringLength(200)]
        [Required]
        public string CompanyName { get; set; }

        /// <summary>
        /// 关于商家
        /// </summary>
        [Column("About",TypeName="nvarchar")]
        [StringLength(2000)]
        public string About { get; set; }

        /// <summary>
        /// 公司地址
        /// </summary>
        [Column("Location",TypeName="nvarchar")]
        [StringLength(200)]
        public string Location { get; set; }

        /// <summary>
        /// 联系电话
        /// </summary>
        [Column("Phone",TypeName="nvarchar")]
        [StringLength(200)]
        public string Phone { get; set; }

        /// <summary>
        /// 联系邮箱
        /// </summary>
        [Column("EMail",TypeName="nvarchar")]
        [StringLength(200)]
        public string EMail { get; set; }
        
        ///// <summary>
        ///// 是否是官方认证商家
        ///// </summary>
        //[Column("Identification",TypeName="bit")]
        //public bool Identification { get; set; }

        ///// <summary>
        ///// 审核认证Id
        ///// </summary>
        //[Column(TypeName="int")]
        //public int CertificationId { get; set; } 
        /// <summary>
        /// 企业认证级别
        /// </summary>
        [Column("CertificationLevel", TypeName = "int")]
        public int CertificationLevel { get; set; }
        #endregion

        public override int PostModify()
        {
            if (!String.IsNullOrEmpty(this.Agent))
            {
                ueCache.RemoveCache("GetCorporation:" + Agent);
            }
            return base.PostModify();
        }
    }
}
